package edu.szte.ovrt.datahandler.xml;

import java.io.StringWriter;

import static edu.szte.ovrt.datahandler.test.ModelFactory.*;

import javax.xml.stream.XMLStreamException;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

import edu.szte.ovrt.datahandler.core.DocumentWriter;
import edu.szte.ovrt.datahandler.core.DocumentWriterException;
import edu.szte.ovrt.datahandler.model.Document;

public class XMLWriterTest {
	@Test
	public void testWriteDocumentEmpty() throws XMLStreamException, DocumentWriterException {
		skeletonWrite(DOCUMENT_EMPTY_XML, createDocumentEmpty());
	}

	@Test
	public void testWriteDocument() throws XMLStreamException, DocumentWriterException {
		skeletonWrite(DOCUMENT_ONE_SECTION_XML, createDocumentWithOneSection());
	}

	@Test
	public void testWriteDocumentFull() throws XMLStreamException, DocumentWriterException {
		skeletonWrite(DOCUMENT_FULL_XML, createDocumentFull());
	}

	private void skeletonWrite(final String expected, final Document document) throws XMLStreamException, DocumentWriterException {
		final StringWriter writer = new StringWriter();
		final DocumentWriter xmlWriter = new XMLWriter(writer);

		xmlWriter.write(document);

		assertEquals(expected, writer.toString());
	}
}
